package com.google.code.memoriesalbum.controller.admin;

import java.io.IOException;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.google.appengine.api.datastore.KeyFactory;
import com.google.code.memoriesalbum.model.Account;
import com.google.code.memoriesalbum.model.PicasaAlbum;
import com.google.code.memoriesalbum.service.AlbumService;
import com.google.gdata.client.authn.oauth.OAuthException;
import com.google.gdata.util.ServiceException;

/**
 * ユーザが保持する{@link PicasaAlbum}の情報を新しくFetchしたものに更新する。
 * <p>{@link Account}の主キーのエンコード文字列。</p>
 * @author shin1ogawa
 */
public class FetchAlbumList extends Controller {

	@Override
	public Navigation run() {
		String accountKeyString = request.getParameter("key");
		try {
			AlbumService.fetchAlbumList(KeyFactory.stringToKey(accountKeyString));
			return null;
		} catch (OAuthException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		} catch (ServiceException e) {
			throw new RuntimeException(e);
		}
	}
}
